﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Brain;
using Microsoft.Xna.Framework;
using Brain.Rendering;
using Microsoft.Xna.Framework.Graphics;

namespace Demos
{
    public class MainMenuScreen : GameScreen
    {
        public MenuSystem System;

        public Sprite MouseSprite;

        public class ScreenData
        {
            public string Name;
            public Type ScreenType;
            public string Description;

            public ScreenData(string name, Type screenType, string description)
            {
                this.Name = name;
                this.ScreenType = screenType;
                this.Description = description;
            }
        }

        private static ScreenData[] AllScreens = new ScreenData[]
        {
            // Farseer Sample is still on test on Windows
#if WINDOWS && !MONOGAME
            new ScreenData("2D - Farseer Physics", typeof(FarseerSample), 
                "Showns an example of animating Sprites \nwith the use of Animation_Vector2" +
                "\n\n\n Controls \nBACKSPACE - Return\n" +
                "\nPress ENTER to Begin"),
#endif
            new ScreenData("2D - Bezier Curves", typeof(BezierCurve2DSample), 
                "Showns an example of animating Sprites \nwith the use of Animation_Vector2" +
                "\n\n\n Controls \nBACKSPACE - Return\n" +
                "\nPress ENTER to Begin"),
           new ScreenData("2D - Rectangle Center Position", typeof(RectangleCenterPosition), 
                "Showns an example of animating Sprites \nwith the use of Animation_Vector2" +
                "\n\n\n Controls \nBACKSPACE - Return\n" +
                "\nPress ENTER to Begin"),
            new ScreenData("2D - Sprite Animation Sample 1", typeof(AnimateSprite), 
                "Showns an example of animating Sprites \nwith the use of Animation_Vector2" +
                "\n\n\n Controls \nBACKSPACE - Return\n" +
                "\nPress ENTER to Begin"),
            new ScreenData("2D - Sprite Animation Sample 2", typeof(AnimateSprite2), 
                "Showns an example of animating Sprites \nwith the use of Animation_Sprite" +
                "\n\n\n Controls \nBACKSPACE - Return\n" +
                "\nPress ENTER to Begin"),
            new ScreenData("2D - Camera 2D", typeof(Camera2DSample), 
                "Shows the Camera 2D System, that makes easy \nto zoom in/out and move between sprites" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nMouse Wheel/Right Thumbstick - Zoom In/Out Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
            new ScreenData("2D - Path Finding", typeof(PathFinding2DTestTiled), 
                "Shows a simple map with a start and end, \n with a way found by the PathFinder" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nMouse Wheel/Right Thumbstick - Zoom In/Out Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
            new ScreenData("2D - Path Finding 2", typeof(PathFinding2DTestTiled2), 
                "Shows a more advanced Map, made from a texure" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nMouse Wheel/Right Thumbstick - Zoom In/Out Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
#if XBOX
           new ScreenData("3D - Little City of Boxes", typeof(AvatarTestScreen), 
                "Shows default Rendering Possibilities of Brain(BasicEffect),\nalong with Array System utilities" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
#endif
                
            new ScreenData("3D - Little City of Boxes", typeof(LittleCityOfBoxesScreen), 
                "Shows default Rendering Possibilities of Brain(BasicEffect),\nalong with Array System utilities" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
#if MONOGAME
            new ScreenData("3D - Bepu Wall", typeof(BepuWall), 
                "Shows default Rendering Possibilities of Brain(BasicEffect),\nalong with Array System utilities" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
#endif
#if !MONOGAME
            new ScreenData("3D - Bullets Test", typeof(Bullets), 
                "Shows Brain's Bullet System" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nLeft Mouse Button/RT - Shoot\nPress ENTER to Begin"),
#endif
            new ScreenData("3D - AI Battle", typeof(AIBattle), 
                "Shows the Beginning of the AI, in an endless cross-battle" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
            new ScreenData("3D - Skinning", typeof(SkinningScreen), 
                "Shows the Beginning of the AI, in an endless cross-battle" +
                "\n\n\n Controls \nWASD/Left Thumbstick - Movement\nRight Mouse Button/Right Thumbstick - Rotate Camera\nR/RB - Reset Camera Position" +
                "\nPress ENTER to Begin"),
        };

        public MainMenuScreen()
        {
            System = new MenuSystem(1, 15);
            System.Animation = new MainMenu_Animation();

            SpriteFont font = Engine.Instance.ContentManager.Load<SpriteFont>("Game\\Fonts\\Segoe24");

            int X = 50;
            int Y = 50;
            for (int i = 0; i < AllScreens.Length; i++)
            {
                ScreenData data = AllScreens[i];

                Sprite sprite = new Sprite();
                sprite.Text = data.Name;
                sprite.Rendering = SpriteRendering.Rendered;
                sprite.SpriteFont = font;
                sprite.Shadow = 2;
                sprite.Position = new Vector2(X, Y + (Y * i));

                MenuEntry_Sprite entry = new MenuEntry_Sprite(sprite);
                System.AddEntry(entry, 0, i);
                entry.OnSelected += new SetMenuEntry(entry_OnSelected);
            }

            MouseSprite = new Sprite();
            MouseSprite.TexturePlace = "Game\\Textures\\my mouse";
            MouseSprite.Rendering = SpriteRendering.Rendered;
        }

        void entry_OnSelected(MenuEntry entry)
        {
            int index = entry.Y;
            ScreenData data = AllScreens[index];

            Engine.Instance.Reset();

            GameScreen gs = (GameScreen)Activator.CreateInstance(data.ScreenType);
            gs.ShouldDraw = false;
            gs.ShouldUpdate = false;

            DescriptionScreen description = new DescriptionScreen(data.Name, data.Description, gs);
        }

        public override void Update()
        {
            base.Update();

            System.Update();

            MouseSprite.Position = Engine.Instance.InputManager.GetMousePosition();
        }

        public override void Draw()
        {
            base.Draw();
        }
    }
}
